package com.atguigu.bean;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class Cat implements InitializingBean,DisposableBean {

	@Autowired
	private ApplicationContext applicationContext;

	public Cat(){
		System.out.println("cat constructor...");
	}

	/**
	 * 注意这个执行时机：在容器销毁bean之前通知我们进行清理工作。。。是在销毁bean之前，不然你都销毁完了我数据库连接还有必要再关闭吗？
	 * @throws Exception
	 */
	@Override
	public void destroy() throws Exception {
		System.out.println("cat...destroy...");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		//这是自定义初始化方法哦，并非初始化前后
		System.out.println("cat...afterPropertiesSet...");
		System.out.println(applicationContext.getBeanDefinitionCount());
	}



}
